﻿using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;
using MyProject.Entities.Address;
using MyProject.Entities.Config;
using MyProject.Entities.EmploymentContract;
using MyProject.Entities.ListItem;
using MyProject.Entities.Passport;
using MyProject.Entities.User;
namespace MyProject.Core
{
    public class MyDbContext : DbContext
    {
        public DbSet<ListItem> ListItem { get; set; }
        public DbSet<Address> Addresses { get; set; }
        public DbSet<Passport> Passport { get; set; }
        public DbSet<User> User { get; set; }
        public DbSet<EmploymentContract> EmploymentContract { get; set; }

        public MyDbContext() : base()
        {
           Database.EnsureCreated();
        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            var config = new AppConfig();

            string? connectionString = config.GetConnectionString;

            if (!connectionString.IsNullOrEmpty())
            {
                optionsBuilder.UseSqlServer(connectionString + "Encrypt=False");
            } else
            {
                optionsBuilder.UseSqlite("Data Source=MyProject.db");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            ListItem departments = new ListItem("Отделы МВД", 0, "departments", 1);
            ListItem address = new ListItem("Адреса", 0, "address", 2);

            ListItem city1 = new ListItem("Ростов на Дону", (int)address.id, "city", 3);
            ListItem city2 = new ListItem("Новочеркасск", (int)address.id, "city", 4);
            ListItem city3 = new ListItem("Краснодар", (int)address.id, "city", 5);
            ListItem city4 = new ListItem("Москва", (int)address.id, "city", 6);


            modelBuilder.Entity<ListItem>().HasData(
                departments,
                address,
                city1,
                city2,
                city3,
                city4,
                new ListItem("Отдел МВД по Ростовской области", (int)departments.id, null, 7),
                new ListItem("Отдел МВД по Краснодарскому краю", (int)departments.id, null, 8),
                new ListItem("Отдел МВД по Ставропольскому краю", (int)departments.id, null, 9),
                new ListItem("Отдел МВД по Липецкой области", (int)departments.id, null, 10),
                new ListItem("Отдел МВД по Московской области", (int)departments.id, null, 11),
                new ListItem("Ленина", (int)city1.id, "street", 12),
                new ListItem("Ленина", (int)city2.id, "street", 13),
                new ListItem("Ленина", (int)city3.id, "street", 14),
                new ListItem("Ленина", (int)city4.id, "street", 15),
                new ListItem("Пушкина", (int)city1.id, "street",16),
                new ListItem("Пушкина", (int)city2.id, "street", 17),
                new ListItem("Пушкина", (int)city3.id, "street", 18),
                new ListItem("Пушкина", (int)city4.id, "street", 19),
                new ListItem("Московская", (int)city1.id, "street", 20),
                new ListItem("Московская", (int)city2.id, "street", 21),
                new ListItem("Московская", (int)city3.id, "street", 22),
                new ListItem("Ставропольская", (int)city3.id, "street", 23),
                new ListItem("Авиамоторная", (int)city4.id, "street", 24),
                new ListItem("Ангарская", (int)city4.id, "street", 25),
                new ListItem("Бажова", (int)city4.id, "street", 26),
                new ListItem("Вавилова", (int)city4.id, "street", 27),
                new ListItem("Гагарина", (int)city4.id, "street", 28),
                new ListItem("Кабельная 1-я", (int)city4.id, "street", 29),
                new ListItem("Ладожская 1-я", (int)city4.id, "street", 30),
                new ListItem("Максимова 1-я", (int)city4.id, "street", 31),
                new ListItem("1-го мая", (int)city3.id, "street", 32),
                new ListItem("2я Школьная", (int)city3.id, "street", 33),
                new ListItem("Академика Трубилина", (int)city3.id, "street", 34),
                new ListItem("Бабушкина", (int)city3.id, "street", 35),
                new ListItem("Дежнёва", (int)city3.id, "street", 36),
                new ListItem("Яхонтовая", (int)city3.id, "street", 37),
                new ListItem("Южная", (int)city3.id, "street", 38),
                new ListItem("Атаманская", (int)city2.id, "street", 39),
                new ListItem("Виноградная", (int)city2.id, "street", 40),
                new ListItem("Мацоты", (int)city2.id, "street", 41),
                new ListItem("Просвещения", (int)city2.id, "street", 42),
                new ListItem("Рабочий Городок", (int)city2.id, "street", 43),
                new ListItem("Троицкая", (int)city2.id, "street", 44),
                new ListItem("Чехова", (int)city2.id, "street", 45),
                new ListItem("Энгельса", (int)city2.id, "street", 46),
                new ListItem("2-я Краснодарская", (int)city1.id, "street", 47),
                new ListItem("50-летия Ростсельмаша", (int)city1.id, "street", 48),
                new ListItem("Вавилова", (int)city1.id, "street", 49),
                new ListItem("Лесная", (int)city1.id, "street", 50),
                new ListItem("Магнитогорская", (int)city1.id, "street", 51),
                new ListItem("Мечникова", (int)city1.id, "street", 52),
                new ListItem("Освобождения", (int)city1.id, "street", 53)
                );
        }


    }
}
